
// 正则 [00:00.00] 作词 : G.E.M.邓紫棋
const timeReg = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/
export function parseLyric(lrcString){
  const lyricInfos = []
  const lyricLines = lrcString.split("\n")
  for(const [index, lyricLine] of lyricLines.entries()){
    const res = timeReg.exec(lyricLine) //"[00:24.18]", "00", "24", "18"
    if(!res)continue  //有可能存在空行正则匹配不上
    const minute = res[1] * 60 * 1000
    const second = res[2] * 1000
    // ms如果是两位需要*10，
    const msecond = res[3].length === 2 ? res[3] * 10 : res[3] * 1
    const time = minute + second + msecond
    const text = lyricLine.replace(timeReg, "")
    lyricInfos.push({time, text, lyricLineIndex: index})
  }
  return lyricInfos
}